package com.braveo.dict;

import java.util.Iterator;
import java.util.LinkedList;

public class QuickHist {
	private final int HIST_NUMBER = 10;
	private final LinkedList<String> track = new LinkedList<String>();

	private final static QuickHist instance = new QuickHist();
	
	private QuickHist() {
	
	}
	
	
	public static QuickHist getInstance() {
		return instance;
	}
	
	public boolean add(String hist) {
		boolean exists = track.remove(hist);
		if(!exists){
			if(track.size() >= HIST_NUMBER){
				track.removeFirst();
			}
		}
		
		return track.add(hist);
	}

	public void clear() {
		track.clear();
	}

	public boolean contains(Object arg0) {
		return track.contains(arg0);
	}

	public int indexOf(Object arg0) {
		return track.indexOf(arg0);
	}

	public boolean isEmpty() {
		return track.isEmpty();
	}

	public Iterator<String> iterator() {
		return track.iterator();
	}

	public int lastIndexOf(Object arg0) {
		return track.lastIndexOf(arg0);
	}

	public boolean remove(Object arg0) {
		return track.remove(arg0);
	}

	public int size() {
		return track.size();
	}
	
	public String getAllHistories(String left, String seperator, String right){
		StringBuilder sb = new StringBuilder();
		Iterator<String> it = track.iterator();
		while(it.hasNext()){
			String n = it.next();
			sb.append(left);
			sb.append(n);
			sb.append(right);
			if(it.hasNext())
				sb.append(seperator);
		}
		return sb.toString();
	}
	

}
